﻿using DigitalScreen.Models;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using LiveCharts.Wpf.Charts.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace DigitalScreen.ViewModels
{
    public class MainViewModel
    {
        public SeriesCollection StateSeries { get; set; }
        public ChartValues<ObservableValue> YeildValue1 { get; set; } = new ChartValues<ObservableValue>();
        public ChartValues<ObservableValue> YeildValue2 { get; set; } = new ChartValues<ObservableValue>();
        public List<CompareItemModel> WorkerCompareList { get; set; }
        public List<CompareItemModel> QualityList { get; set; } = new List<CompareItemModel>();

        public List<BadItemModel> BadItemModelList { get; set; } = new List<BadItemModel>();
        public List<string> Alarms { get; set; }

        public string CurrentYeild { get; set; } = "123456";
        public int FinishRate { get; set; } = 80;

        CancellationTokenSource cts = new CancellationTokenSource();
        Task task = null;
        Random random = new Random();
        public MainViewModel()
        {
            #region 环状图数据
            StateSeries = new SeriesCollection();
            StateSeries.Add(new PieSeries()
            {
                Title = "普货",
                Values = new ChartValues<double>(new double[] { 0.533 }),
                Fill = new SolidColorBrush(Color.FromArgb(255, 43, 182, 254))
            });
            StateSeries.Add(new PieSeries()
            {
                Title = "普货",
                Values = new ChartValues<double>(new double[] { 0.2 })
            });
            StateSeries.Add(new PieSeries()
            {
                Title = "普货",
                Values = new ChartValues<double>(new double[] { 0.167 })
            });
            StateSeries.Add(new PieSeries()
            {
                Title = "普货",
                Values = new ChartValues<double>(new double[] { 0.1 })
            });
            #endregion

            #region 人员绩效
            string[] Empolys = new string[] { "赵有才", "王福", "孙德顺", "李**", "周**", "赵有才", "王福", "孙德顺", "李**", "周**" };
            WorkerCompareList = new List<CompareItemModel>();
            foreach (var e in Empolys)
            {
                WorkerCompareList.Add(new CompareItemModel()
                {
                    Name = e,
                    PlanValue = random.Next(100, 200),
                    FinishedValue = random.Next(50, 180)
                });

            }
            #endregion

            #region 报警数据初始化
            Alarms = new List<string>();
            Alarms.Add("[H338 -> 厂务冷却水入水温度[℃]] 34->10:00");
            Alarms.Add("[H338 -> 厂务冷却水入水温度[℃]] 34->10:00");
            Alarms.Add("[H338 -> 厂务冷却水入水温度[℃]] 34->10:00");
            Alarms.Add("[H338 -> 厂务冷却水入水温度[℃]] 34->10:00");
            Alarms.Add("[H338 -> 厂务冷却水入水温度[℃]] 34->10:00");
            #endregion

            #region lineChart

            for (int i = 0; i < 12; i++)
            {
                YeildValue1.Add(new ObservableValue(random.Next(20, 380)));
                YeildValue2.Add(new ObservableValue(random.Next(20, 330)));
            }
            #endregion

            #region 不良
            string[] BadNames = new string[] { "缺角A", "缺角B", "缺角C", "缺角D", "缺角E", "缺角F", "缺角G", "缺角B" };
            for (int i = 0; i < BadNames.Length; i++)
            {
                BadItemModelList.Add(new BadItemModel { Title = BadNames[i], Size = 180 - 20 * i, Value = 0.9 - 0.1 * i });
            }
            #endregion

            #region 质量控制
            string[] quality = new string[] { "机床-1", "机床-2", "机床-3", "机床-4", "机床-5", "机床-6", "机床-7", "机床-8" };
            foreach (var e in quality)
            {
                QualityList.Add(new CompareItemModel()
                {
                    Name = e,
                    PlanValue = random.Next(100, 200),
                    FinishedValue = random.Next(50, 180)
                });
            }

            #endregion

            task = Task.Run(() =>
            {
                while (!cts.IsCancellationRequested)
                {

                }
            }, cts.Token);
        }

        public void Dispose()
        {
            cts.Cancel();
            Task.WaitAny(task);
        }
    }
}

